<?php
$csvfile = "pmek.csv";
$outputfile = "pmek.sql";
$startindex = 1;

/***********************************************/
function processRow($counter, $rowdata, $out) {
    $city = $rowdata[0];
    $county = $rowdata[1];
    $zipcode = $rowdata[2];
    $addr = $rowdata[3];
    $mayor = $rowdata[4];
    $email1 = $rowdata[5];
    $phone = $rowdata[6];
    $contactperson = $rowdata[7];
    $contactemail = $rowdata[8];
    $contactphone = $rowdata[9];

    $insert1 = "INSERT INTO lst_pm (city, county, zipcode, mayor, email, phone, contactperson, contactemail, contactphone) ".
              "VALUES ('$city', '$county', '$zipcode', '$mayor', '$email1', '$phone', '$contactperson', '$contactemail', '$contactphone');\r\n";
    fputs($out, $insert1);
}
/***********************************************/

$f = fopen($csvfile, "r");
$c = 0;
$out = fopen($outputfile,  "w");
$counter = $startindex;
while (!feof($f)) {
    $c++;
    $row = rtrim(fgets($f));
    if ($c == 1) { continue; }
    $row = str_replace("\"", "", $row);
    $row = str_replace("'", "''", $row);
    $rowdata = explode(";", $row);
    processRow($counter, $rowdata, $out);
    $counter++;
}
fclose($f);
fclose($out);
?>
